if(POLICY CMP0167)
    cmake_policy(SET CMP0167 NEW)
endif()

# 启用CTest
include(CTest)
enable_testing()  # 启用测试功能

find_package(OpenCL REQUIRED)
find_package(Boost REQUIRED COMPONENTS log log_setup random timer filesystem)

add_compile_definitions(CL_TARGET_OPENCL_VERSION=300)

add_compile_definitions(CURRENT_DIR_NAME="${CMAKE_CURRENT_SOURCE_DIR}")

# 分别处理测试文件和非测试文件
file(GLOB TEST_FILES test_*.cpp)
file(GLOB SRC_FILES *.cpp)

# 为测试文件单独创建目标并添加到CTest
foreach(test_file ${TEST_FILES})
    get_filename_component(target ${test_file} NAME_WE)
    add_executable(${target} ${test_file})
    target_link_libraries(${target} PRIVATE OpenCL::OpenCL Boost::log Boost::log_setup Boost::random Boost::timer Boost::filesystem)
    add_test(NAME ${target} COMMAND ${target})
endforeach()

# 为非测试文件创建目标
foreach(src_file ${SRC_FILES})
    get_filename_component(target ${src_file} NAME_WE)
    # 检查文件是否已经在测试列表中
    if(NOT ${src_file} IN_LIST TEST_FILES)
        add_executable(${target} ${src_file})
        target_link_libraries(${target} PRIVATE OpenCL::OpenCL Boost::log Boost::log_setup Boost::random Boost::timer Boost::filesystem)
    endif()
endforeach()